package com.situ.web.service;

import java.util.List;

import com.situ.web.dao.StudentDao;
import com.situ.web.entity.PageInfo;
import com.situ.web.entity.Student;

public class StudentService {
	private StudentDao studentDao = new StudentDao();

	public List<Student> findAll() {
		List<Student> list = studentDao.findAll();
		return list;
	}

	public boolean insert(Student student) {
		int count = studentDao.insert(student);
//		if (count == 1) {
//			return true;
//		} else {
//			return false;
//		}
		return count == 1 ? true : false;
	}

	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(pageNo);
		pageInfo.setPageSize(pageSize);
		
		// totalPage：一共有多少页
		int count = studentDao.getTotalCount();
		//  101/5=20
		int totalPage = (int)Math.ceil((double)count / pageSize);
		pageInfo.setTotalPage(totalPage);
		
		// list:当前页要展示的数据的集合
		int offset = (pageNo - 1) * pageSize;
		List<Student> list = studentDao.findByPage(offset, pageSize);
		pageInfo.setList(list);
		
		return pageInfo;
	}
	
	public static void main(String[] args) {
		System.out.println(Math.ceil((double)101/5));;
	}

}
